package eventmanager.frontend;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import eventmanager.backend.Time;
import eventmanager.backend.event.Event;

public class TestGUIEventDetails {

	private JTextField nameField;

	private JComboBox<Object> dayBox, monthBox, yearBox;

	private JLabel nameLabel, dayLabel, monthLabel, yearLabel;

	private JButton addEvent;

	private JPanel panel;
	
	private Time dt;

	public TestGUIEventDetails() {
		JFrame frame = new JFrame();
		panel = new JPanel();
		dt = new Time();
		Integer[] days = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
				16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
		Integer[] years = { 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
				2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029,
				2030 };
		String[] mos = { "January", "February", "March", "April", "May",
				"June", "July", "August", "September", "October", "November",
				"December" };
		frame.setTitle("Event");
		frame.setSize(200, 170);
		frame.setLocationRelativeTo(null);
		nameLabel = new JLabel("Name:");
		dayLabel = new JLabel("Day:");
		dayBox = new JComboBox<Object>(days);
		monthLabel = new JLabel("Month:");
		monthBox = new JComboBox<Object>(mos);
		yearLabel = new JLabel("Year:");
		yearBox = new JComboBox<Object>(years);
		nameField = new JTextField();
		addEvent = new JButton("Add Event");
		addEvent.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("Event Logged");
				String name = nameField.getText();
				int day = dayBox.getSelectedItem().hashCode();
				int month = monthBox.getSelectedIndex() + 1; // +1 to give correct month number
				int year = yearBox.getSelectedItem().hashCode();
				int hour = dt.setHour();
				int min = dt.setMin();
				Event e = new Event(name, month, day, year, hour, min);
				Event.addEvent(e);
				
				
			}
		});
		panel.setBackground(Color.WHITE);

		panel.setLayout(null);

		panel.add(nameField);
		panel.add(dayBox);
		panel.add(monthBox);
		panel.add(yearBox);
		panel.add(nameLabel);
		panel.add(dayLabel);
		panel.add(monthLabel);
		panel.add(yearLabel);
		panel.add(addEvent);

		nameLabel.setBounds(5, 5, 50, 20);
		nameField.setBounds(75, 5, 100, 20);
		dayLabel.setBounds(5, 30, 50, 20);
		dayBox.setBounds(75, 30, 100, 20);
		monthLabel.setBounds(5, 55, 50, 20);
		monthBox.setBounds(75, 55, 100, 20);
		yearLabel.setBounds(5, 80, 50, 20);
		yearBox.setBounds(75, 80, 100, 20);
		addEvent.setBounds(43, 105, 100, 20);
		
		frame.add(panel);
		frame.setVisible(true);

	}
}
